package services.gsgl;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import com.Const;
import com.PublicSystem;
public class KTgsServices {
	/**
	 * 口头挂失
	 * @author host
	 *
	 */
	PublicSystem sys = PublicSystem.getInstance();	
	/**
	 * 银行下拉框选项
	 * @param sj
	 * @return
	 * @throws Exception
	 */
	public List getYinhang(String sj) throws Exception {
		String sql = "select aaa103,aaa102 from v_ic_az11 where aaa100=?";
		List data = sys.query(sql, new Object[] {sj}, true);
		return data;
	}
	/**
	 * 查询单位登记信息
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	public String checkdata(HashMap obj) throws Exception {		
		String ss = sys.callDBFuncProce("ic_gsgl.chk_gsgl", "function", obj).toString();
		String[] msg = ss.split("&");
		String result = msg[0];
		return result;
	}	
	/**
	 * 获取单位登记信息
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	public HashMap getdata(String id) throws Exception {		
		String sql = "select AAC003,AAC004,AAC002,AAC046,AAC006,AAC005 from AZ20 t where t.aac001=?" 
				+ "and t.AAE036=(select max(AAE036) from az20 where aac001=?) ";
		List data = sys.query(sql, new Object[] {id, id}, true);
		String sql1 = "select aac100 from az02 where AAC001='" + id + "'";       
		String path = Const.server_path + "/Picture/";
		String name = id  + "." + "JPG";
		String file = path + name;
		File files = new File(path);
		if(!files.exists()) {		
			files.mkdirs();
		}	
		boolean flag = sys.SelResultBlob(sql1, file);
		HashMap map = new HashMap();
		if(data.size() > 0) {		
			map = (HashMap)data.get(0);
			String sql2 = "select b.aab001,b.aab004,a.AAC010 from aca1 a, ab01 b where a.aab001=b.aab001 and a.AAC001=?";
			List data2 = sys.query(sql2, new Object[] {id}, true);
			if(data2.size() > 0 ) { 			
				HashMap obj = (HashMap)data2.get(0);
				map.put("aab001", obj.get("aab001"));
				map.put("aab004", obj.get("aab004"));
				map.put("aac010", obj.get("aac010"));
			}
			String sql3 = "select AAE009,AAE008 from AZ19 where AAC001=?";
			List data3 = sys.query(sql3, new Object[] {id}, true);
			if(data3.size() > 0 ) {		 
				HashMap obj = (HashMap)data3.get(0);
				map.put("aae009", obj.get("aae009"));
				map.put("aae008", obj.get("aae008"));
			}
		}
		else {		
			return null;
		}
		return map;
	}	
	/**
	 * 下拉框选项
	 * @param lx
	 * @return
	 * @throws Exception
	 */
	public List getSelect(String lx) throws Exception {
		String sql = "select aaa103,aaa102 FROM aa10 where aaa100=?";
		List data = sys.query(sql, new Object[] {lx}, true);
		return data;
	}	
	/**
	 * 校验导入
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	public String savedata(HashMap obj) throws Exception {	
		obj.put("aaz767", "1");
		String ss = sys.callDBFuncProce("ic_gsgl.set_ktgs", "function", obj).toString();
		String[] str = ss.split("&");	
		String result = str[0];		
		return result;
	} 
}
